package com.cztv.vote.servlet;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.cztv.vote.bean.VoteProjectBean;
import com.cztv.vote.service.VoteManager;

public class VoteServlet extends HttpServlet {
	private static final long serialVersionUID = -8698433209681275904L;
	private   VoteManager voteManager;
	
	@Required
	public void setVoteManager(VoteManager voteManager) {
		this.voteManager = voteManager;
	}

	@Override
	public void init(ServletConfig config) throws ServletException {
		  ServletContext servletContext = config.getServletContext();
		  WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
		  AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext.getAutowireCapableBeanFactory();
		  autowireCapableBeanFactory.configureBean(this, "voteManager");
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		VoteProjectBean bean=voteManager.getVoteProjectInfo(1);
		System.out.println(bean.getIpTimeLimit());
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
	}
	
	public static void main(String[] args){
		
	}

}
